import Vue from 'vue'
import Vuex from 'vuex'
import state from './state'
import createLogger from 'vuex/dist/logger'
//全局引用
Vue.use(Vuex)
const debug = process.env.NODE_ENV !== 'production'

const store = new Vuex.Store({
	state,
	getters:{
		getCount:(state)=>{
			return state.count=state.count<10?"0"+state.count:state.count
		},
		getCurTid:(state)=>{
			let partitionList=window.__INITIAL_STATE__.reduxAsyncConnect.partitionList
			const hasCon=partitionList[state.curTid]
			if(!hasCon){
				const keyArr=Object.keys(partitionList)//存入键名
				for(let i=0,len=keyArr.length;i<len;i++){
					const tmpArr=partitionList[keyArr[i]]
					for(let j=0;j<tmpArr.length;j++){
						if(tmpArr[j].tid==state.curTid){
							return state.curTid=keyArr[i]
						}
					}
				}
			}else{
				return state.curTid
			}
		}
	},
	mutations:{
		increment (state){
			state.count++;
		},
		setCurTid(state,payload){
			state.curTid=payload.curTid
		}
	},
	plugins:debug ? [createLogger()] : []
})

export default store



//count:this.$store.state.count

//count(){
//	return this.$store.state.count
//}
